﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Viettel.VOFFICE.Web.Helpers
{
    public class MvcHelper
    {
        public static List<Type> GetSubClasses<T>()
        {
            return AppDomain
                .CurrentDomain
                .GetAssemblies()
                .SelectMany(
                    a => a.GetTypes().Where(type => type.IsSubclassOf(typeof(T)))
                ).ToList();
        }

        public List<string> GetControllerNames()
        {
            var controllerNames = new List<string>();
            GetSubClasses<Controller>().ForEach(
                type => controllerNames.Add(type.Name));
            return controllerNames;
        }

        public List<string> GetShortlyControllerNames()
        {
            var controllerNames = new List<string>();
            GetSubClasses<Controller>().ForEach(
                type => controllerNames.Add(type.Name.Replace("Controller","")));
            return controllerNames;
        }
        public List<string> GetAttrControllerNames()
        {
            var attrController = new List<string>();
            GetSubClasses<Controller>().ForEach(
                type => attrController.Add(GetAttrHelper.Get(type)));
            return attrController;
        }
    }
}